import { UserLoginSuccessDto, UserPersistDto } from "@/types/userType.js";

export const saveUserInfo = (userLoginSuccessDto: UserLoginSuccessDto) => {
    localStorage.setItem('id', userLoginSuccessDto.id.toString());
    localStorage.setItem('name', userLoginSuccessDto.name);
    localStorage.setItem('bio', userLoginSuccessDto.bio);
    localStorage.setItem('avatar', userLoginSuccessDto.avatar);
}

export const clearUserInfo = () => {
    localStorage.removeItem('id');
    localStorage.removeItem('name');
    localStorage.removeItem('bio');
    localStorage.removeItem('avatar');
}

export const getUserInfo = (): UserPersistDto => {
    return {
        id: Number(localStorage.getItem('id')),
        name: localStorage.getItem('name'),
        bio: localStorage.getItem('bio'),
        avatar: localStorage.getItem('avatar'),
    } as UserPersistDto;
};
